﻿using System;
using System.IO;
using System.Xml;
using System.Configuration;
using System.Web;
using SyCODE.Component.DataFactory;
using System.Collections.Specialized;
using SyCODE.Component.Security;
using SyCODE.Component;
using System.Web.Security;

/// <summary>
/// SyCODE 的摘要说明
/// </summary>
namespace SyCODE.Blog
{
    /// <summary>
    /// 获得个人消息列表
    /// </summary>
    public class GetMessage : IHttpHandler
    {
        #region IHttpHandler 成员

        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
			Ticket ticket = Ticket.Get(FormsAuthentication.FormsCookieName);
            if (Ticket.Authenticate(ticket))
            {
                context.Response.ContentType = "text/xml";

                NameValueCollection nvc = new NameValueCollection(context.Request.Form);
                nvc.Add("u", ticket.Name);

                DBAM dbam = new DBAM();
                dbam.BuildParameters("message", nvc);

                XmlTextWriter writer = new XmlTextWriter(context.Response.OutputStream, context.Response.ContentEncoding);
                writer.WriteStartDocument();

                try
                {
                    dbam.ExecuteXmlTextWriter(writer, context.Request.Form);
                }
                finally
                {
                    dbam.Dispose();
                }

                writer.WriteEndDocument();

                writer.Flush();
            }
            else
            {
                Function.ClientAlert(StringResource.GetField("authfaild"));
            }
        }
        #endregion
    }
}